package tcp_net.mail.pop3.commands;

import tcp_net.mail.MailBoxFileManager;
import tcp_net.mail.pop3.commands.debug.DebugInfo;

import java.util.List;
import java.util.ArrayList;

/**
	This class provides a defined command to be executed
	@author J. Okuno
*/
public class UIDL extends POP3Command 
{
	/**
		A message number
	*/
	private int msg;
	
	/**
		Init the class
		@param m a message number
		@param man a mailbox file manager
	*/
	public UIDL(int m, MailBoxFileManager man) 
	{
		super(man);
		msg = m; 
	}
	
	/**
		Init the class
		@param man a mailbox file manager
	*/
	public UIDL(MailBoxFileManager man) 
	{ 
		this(-1, man); 
	}
	
	/**
		This method executes a defined command
		@return a list of reply messages in a string format
	*/
	public List<String> execute() 
	{ 
		//reply
		reply = new POP3ReplyMessage(true);
		
		if(msg < 0) 
		{
			reply_msgs.add(reply.execute().get(0));
			
			int count = 1;
			for(String id : manager.getAllUniqueIds())
			{
				reply_msgs.add(count+". "+id);
				count++;
			}
		
			reply_msgs.add(".");
		
		}
		else 
		{
			reply_msgs.add(reply.execute().get(0)+" "+manager.getUniqueId(msg));
		}
		
		return reply_msgs;
	}
}